package com.uvnos4j.matilda.system.controller;

import cn.hutool.json.JSONObject;
import com.uvnos4j.matilda.commons.dto.Result;
import com.uvnos4j.matilda.commons.utils.IEnumUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 枚举 Controller
 * <p>
 * Description:枚举 Controller
 * </p>
 *
 * @author Guo.wl
 * @version v1.0.0
 * @see com.uvnos4j.matilda.system.controller
 * @since 2020-08-31 22:33:15
 */
@RestController
@RequestMapping("/sys/enum")
public class EnumController {

    @GetMapping("/{clazzName}")
    public Result get(@PathVariable("clazzName") String clazzName) {
        try {
            Class<? extends Enum> clazz = (Class<? extends Enum>) Class.forName(clazzName);
            JSONObject json = IEnumUtil.getTextValueJson(clazz);
            return Result.success(json);
        } catch (Exception e) {
            return Result.fail(e.getMessage());
        }
    }

}